c   PROGRAM TOTALBUD
c
c   created 7-94, b. stolp
c
c program creates a budget table called --bud.tab--
c from the transient model output file --trmodel--
c Run the program from /input/trans/tr49-90 directory
c
c Step one, filter the model output using awk/bud.sh
c issue command awk/bud.sh >bud1 to send the filtered output to file --bud1--
c 
c program asks for the number of budget items in model output (e.g 7)
c and the number of budgets that are printed  in model output (e.g 42)
c 
c once the ouput table --bud.tab-- is created, you can load it into
c tactitian for graphing and manipulation
c
c
      dimension ain(200,10), aout(100,20)
      open(UNIT = 20,FILE = 'bud1',STATUS = 'UNKNOWN')
      open(UNIT = 21,FILE = 'bud.tab',STATUS = 'UNKNOWN')
      write(6,*)'how many budget items'
      read(5,1020)ione
      write(6,*)'how many printed budgets'
      read (5,1020)itwo
      ithree = 2*itwo
      ifour = 2*ione
      ifive = ifour - 1

      DO 30 j = 1,ione                                                   7
         do 60 i=1,ithree                                                84
      READ(20,1000)ain(i,j)
 60    continue
 30    continue
       inumber = 0
       jnumber = 0
       k = 0

       do 31 j=1,ifive,2                                                 13
       inumber = 0
       k = k + 1
          do 32 i=1,itwo
             aout(i,j) = ain(i+inumber,k)
             inumber = inumber+1
 32          continue
 31          continue


             jnumber = 0
             k = 0
       do 33 j=2,ifour,2                                                 14
          k = k + 1
          do 34 i=1,itwo                                                 42
             aout(i,j) = ain(i*2,k)
 34       continue
 33    continue




       WRITE(21,*)'   sto in/out;','         chd in/out; ',
     c'      well in/out; ','      drn in/out;','
     c     rch in/out; ','        et in/out; ','
     c       str in/out; '

       DO 40 I = 1,itwo                                                  42
       write(21,1010)(aout(i,j),j=1,ifour)                               14
 50     continue
 40    CONTINUE
 1000  format(f9.0)
 1010  format(14f9.0)
 1020  format(i3)
       stop
       end

